using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace UsrControls
{
    public class CheckBoxTemplate : ITemplate
    {
        string _colName = String.Empty;
        string _id = String.Empty;
        string _cssClass = String.Empty;
        string _onClick = String.Empty;

        public CheckBoxTemplate(string id, string columnName)
        {
            _colName = columnName;
            _id = id;
        }

        public CheckBoxTemplate(string id, string columnName, string onClick)
        {
            _colName = columnName;
            _id = id;
            _onClick = onClick;
        }


        //<asp:Label CssClass="textBold" id="lblColumnTotalDay_0" runat="server" />

        public void InstantiateIn(Control container)
        {
            CheckBox chkBox = new CheckBox();
            chkBox.ID = _id;

            if (_cssClass != null && _cssClass != String.Empty)
            {
                chkBox.Attributes.Add("class", _cssClass);
            }

            if (_onClick != null && _onClick != String.Empty)
            {
                chkBox.Attributes.Add("onclick", _onClick);
            }

            if (_colName != null)
            {
                chkBox.DataBinding += new EventHandler(this.OnDataBinding);
            }
            container.Controls.Add(chkBox);
        }

        public void OnDataBinding(object sender, EventArgs e)
        {
            CheckBox chkBox = (CheckBox)sender;
            DataGridItem container = (DataGridItem)chkBox.NamingContainer;
            chkBox.Text = ((DataRowView)container.DataItem)[_colName].ToString();
        }
    }
}
